package com.highper.common.util;

import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.context.model.SaResponse;
import com.highper.common.constant.RequestConstant;
import org.apache.commons.lang3.StringUtils;

/**
 * @Author ZhangGJ
 * @Date 2022/01/26 10:16
 */
public class WebFluxUtil {

    public static String languageWebFlux() {
        String language = null;
        try {
            language = SaHolder.getRequest().getHeader("language");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return StringUtils.isEmpty(language) ? "zh" : language;
    }

    /**
     * 设置异常响应
     *
     * @param contentType content-type
     * @param status      http状态码
     */
    public static void makeExceptionResponse(String contentType, int status) {
        SaResponse response = SaHolder.getResponse();
        response.setHeader(RequestConstant.CONTENT_TYPE, contentType);
        response.setStatus(status);
    }

}
